import math

def calculate_haversine_distance(lon1, lat1, lon2, lat2):
    """计算两个经纬度点之间的距离（米）"""
    R = 6371000  # 地球半径，单位米
    phi1 = math.radians(lat1)
    phi2 = math.radians(lat2)
    delta_phi = math.radians(lat2 - lat1)
    delta_lambda = math.radians(lon2 - lon1)

    a = math.sin(delta_phi / 2.0) ** 2 + \
        math.cos(phi1) * math.cos(phi2) * \
        math.sin(delta_lambda / 2.0) ** 2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    return R * c

def calculate_total_distance_and_duration(waypoints, speed):
    """计算总距离和总时长"""
    total_distance = 0
    if len(waypoints) < 2:
        return 0, 0
    
    for i in range(len(waypoints) - 1):
        p1 = waypoints[i]
        p2 = waypoints[i+1]
        total_distance += calculate_haversine_distance(p1[0], p1[1], p2[0], p2[1])
    
    duration = total_distance / speed if speed > 0 else 0
    return total_distance, duration